package me.lovatcat.springboot.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import me.lovatcat.springboot.demo.domain.dao.IUserDao;
import me.lovatcat.springboot.demo.domain.po.User;
import me.lovatcat.springboot.demo.service.IUserService;
import me.lovetcat.common.base.CrudService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 测试spring启用redis做缓存
 * @author acat on 2017-01-12 17:02
 */
@Service
public class UserService extends CrudService<User, IUserDao> implements IUserService {

    private static final Logger LOG = LoggerFactory.getLogger(UserService.class);

    @Override
    public PageInfo<User> getPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> users = d.getPage();
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

    @Override
    public User getByMobile(String mobile) {
        List<User> users = d.getByMobile(mobile);
        if(!CollectionUtils.isEmpty(users)){
            return users.get(0);
        }
        return null;
    }
}
